﻿using System;
using System.Collections.Generic;

namespace YArchitech.Plumbing
{
	public class ShareRPipeSystem
	{
		public ShareRPipeSystem()
		{
			this.returnPipes = new List<HYPipeData>();
			this.supplyPipes = new List<HYPipeData>();
			this.floorSystems = new List<FloorSystem>();
		}

		public ShareRPipeSystem(ShareRPipeSystem shareRPipe)
		{
			this.preSerialNum = shareRPipe.preSerialNum;
			this.serialNum = shareRPipe.serialNum;
			this.rateUnbalance = shareRPipe.rateUnbalance;
			this.pressActual = shareRPipe.pressActual;
			this.pressCapital = shareRPipe.pressCapital;
			this.flow = shareRPipe.flow;
			this.load = shareRPipe.load;
			this.dPressCapital = shareRPipe.dPressCapital;
			this.dPressControl = shareRPipe.dPressControl;
			this.returnPipes = this.InitialPipeDatas(shareRPipe.returnPipes);
			this.supplyPipes = this.InitialPipeDatas(shareRPipe.supplyPipes);
			this.floorSystems = this.InitialFloorSystems(shareRPipe.floorSystems);
			this.pipeConnForm = shareRPipe.pipeConnForm;
		}

		private IList<FloorSystem> InitialFloorSystems(IList<FloorSystem> floors)
		{
			IList<FloorSystem> list = new List<FloorSystem>();
			if (floors == null || floors.Count < 1)
			{
				return list;
			}
			foreach (FloorSystem floorSystem in floors)
			{
				FloorSystem item = new FloorSystem(floorSystem);
				list.Add(item);
			}
			return list;
		}

		private IList<HYPipeData> InitialPipeDatas(IList<HYPipeData> pipes)
		{
			IList<HYPipeData> list = new List<HYPipeData>();
			if (pipes == null || pipes.Count < 1)
			{
				return list;
			}
			foreach (HYPipeData hyPipe in pipes)
			{
				HYPipeData item = new HYPipeData(hyPipe);
				list.Add(item);
			}
			return list;
		}

		private double GetLoad()
		{
			double num = 0.0;
			for (int i = 0; i < this.FloorSystems.Count; i++)
			{
				num += this.FloorSystems[i].Load;
				this.SupplyPipes[i].Load = 0.0;
				for (int j = i; j < this.FloorSystems.Count; j++)
				{
					this.SupplyPipes[i].Load += this.FloorSystems[j].Load;
				}
				this.ReturnPipes[i].Load = 0.0;
				if (this.PipeConnForm == 1)
				{
					for (int k = 0; k <= i; k++)
					{
						this.ReturnPipes[i].Load += this.FloorSystems[k].Load;
					}
				}
				else
				{
					for (int l = i; l < this.FloorSystems.Count; l++)
					{
						this.ReturnPipes[i].Load += this.FloorSystems[l].Load;
					}
				}
			}
			return num;
		}

		private double GetFlow()
		{
			double num = 0.0;
			for (int i = 0; i < this.FloorSystems.Count; i++)
			{
				num += this.FloorSystems[i].Flow;
				this.SupplyPipes[i].Flow = 0.0;
				for (int j = i; j < this.FloorSystems.Count; j++)
				{
					this.SupplyPipes[i].Flow += this.FloorSystems[j].Flow;
				}
				this.ReturnPipes[i].Flow = 0.0;
				if (this.PipeConnForm == 1)
				{
					for (int k = 0; k <= i; k++)
					{
						this.ReturnPipes[i].Flow += this.FloorSystems[k].Flow;
					}
				}
				else
				{
					for (int l = i; l < this.FloorSystems.Count; l++)
					{
						this.ReturnPipes[i].Flow += this.FloorSystems[l].Flow;
					}
				}
			}
			return num;
		}

		public string PreSerialNum
		{
			get
			{
				return this.preSerialNum;
			}
			set
			{
				this.preSerialNum = value;
			}
		}

		public string SerialNum
		{
			get
			{
				return this.serialNum;
			}
			set
			{
				this.serialNum = value;
			}
		}

		public IList<FloorSystem> FloorSystems
		{
			get
			{
				return this.floorSystems;
			}
			set
			{
				this.floorSystems = value;
			}
		}

		public IList<HYPipeData> SupplyPipes
		{
			get
			{
				return this.supplyPipes;
			}
			set
			{
				this.supplyPipes = value;
			}
		}

		public IList<HYPipeData> ReturnPipes
		{
			get
			{
				return this.returnPipes;
			}
			set
			{
				this.returnPipes = value;
			}
		}

		public int PipeConnForm
		{
			get
			{
				return this.pipeConnForm;
			}
			set
			{
				this.pipeConnForm = value;
			}
		}

		public double DPressControl
		{
			get
			{
				return this.dPressControl;
			}
			set
			{
				this.dPressControl = value;
			}
		}

		public double DPressCapital
		{
			get
			{
				return this.dPressCapital;
			}
			set
			{
				this.dPressCapital = value;
			}
		}

		public double Load
		{
			get
			{
				return this.GetLoad();
			}
			set
			{
				this.load = value;
			}
		}

		public double Flow
		{
			get
			{
				return this.GetFlow();
			}
			set
			{
				this.flow = value;
			}
		}

		public double PressCapital
		{
			get
			{
				return this.pressCapital;
			}
			set
			{
				this.pressCapital = value;
			}
		}

		public double PressActual
		{
			get
			{
				return this.pressActual;
			}
			set
			{
				this.pressActual = value;
			}
		}

		public double RateUnbalance
		{
			get
			{
				return this.rateUnbalance;
			}
			set
			{
				this.rateUnbalance = value;
			}
		}

		private string preSerialNum;

		private string serialNum;

		private IList<FloorSystem> floorSystems;

		private IList<HYPipeData> supplyPipes;

		private IList<HYPipeData> returnPipes;

		private int pipeConnForm;

		private double dPressControl;

		private double dPressCapital;

		private double load;

		private double flow;

		private double pressCapital;

		private double pressActual;

		private double rateUnbalance;
	}
}
